package com.demo.actors;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Align;

public class Progress extends Actor {

	private TextureRegion	bgRegion;
	private TextureRegion	pRegion;
	private float			precent;

	public Progress() {
		bgRegion = new TextureRegion(new Texture("p1.png"));
		setSize(bgRegion.getRegionWidth(), bgRegion.getRegionHeight());

		setOrigin(Align.center);
		pRegion = new TextureRegion(new Texture("p2.png"));
	}

	public void setPrecent(float precent) {
		this.precent = precent;
	}

	@Override
	public void draw(Batch batch, float parentAlpha) {
		super.draw(batch, parentAlpha);

		batch.draw(bgRegion, getX(), getY(), getOriginX(), getOriginY(),
				getWidth(), getHeight(), getScaleX(), getScaleY(),
				getRotation());

		TextureRegion region = new TextureRegion(pRegion, 0, 0,
				(int) (pRegion.getRegionWidth() * precent),
				(int) (pRegion.getRegionHeight()));
		batch.draw(region, getX(), getY(), getOriginX(), getOriginY(),
				region.getRegionWidth(), region.getRegionHeight(), getScaleX(),
				getScaleY(), getRotation());

	}

}
